import Server from 'webpack-dev-server';
import webpack from 'webpack';
import config from './config.js';

import $config from '../jjb.config.json' with { type: 'json' };

if (process.env.NODE_ENV === undefined) {
  console.log('[云组件-Error]: 启动Server需要提供NODE_ENV变量，请确认你所运行的脚本是否正确？');
  process.exit(0);
}

new Server({
  host: $config.server.host || '127.0.0.1',
  port: $config.server.port || '8080',
  headers: {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Methods': '*',
    'Access-Control-Allow-Headers': '*'
  },
  compress: true,
  client: {
    overlay: {
      errors: true,
      warnings: true
    }
  },
  historyApiFallback: {
    disableDotRule: true
  }
}, webpack(config('development'))).startCallback(() => console.log('[云组件]：开发服务已启动。'));
